﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class PlatForm_Default : System.Web.UI.Page
{
	/// <summary>
	/// 问题控制类
	/// </summary>
	private PX.Question.Component clsQuestionComp = new PX.Question.Component();
	/// <summary>
	/// 回答控制类
	/// </summary>
	private PX.Answer.Component clsAnswerComp = new PX.Answer.Component();
	/// <summary>
	/// 大师成果控制类
	/// </summary>
	private PX.ExpertGain.Component clsExpertGainComp = new PX.ExpertGain.Component();

	/// <summary>
	/// 大师课件控制类
	/// </summary>
	private PX.Coureseware.Component clsCoursewareComp;

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			ShowQuestion();
			ShowExpertNews();
			ShowExpertGain();
			ShowCourseware();
		}
	}

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);

		clsQuestionComp.page = Page;
		clsAnswerComp.page = Page;
		clsExpertGainComp.page = Page;
		clsCoursewareComp = new PX.Coureseware.Component(Page);

		GrvExpertGain.RowDataBound += new GridViewRowEventHandler(GrvExpertGain_RowDataBound);
		GrvExpertNews.RowDataBound += new GridViewRowEventHandler(GrvExpertNews_RowDataBound);
		GrvQuestion.RowDataBound += new GridViewRowEventHandler(GrvQuestion_RowDataBound);
		GrvCourseware.RowDataBound += new GridViewRowEventHandler(GrvCourseware_RowDataBound);
	}

	/// <summary>
	/// 大师课件
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void GrvCourseware_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowIndex >= 0)
		{
			for (int i = 0; i < e.Row.Cells.Count; i++)
			{
				HyperLink hLink = new HyperLink();

				hLink.Text = e.Row.Cells[i].Text;
				hLink.Target = "_blank";
				hLink.NavigateUrl = "CoursewareDetail.aspx?CoursewareID=" + GrvCourseware.DataKeys[e.Row.RowIndex].Value.ToString();

				e.Row.Cells[i].Controls.Add(hLink);
			}
		}
	}

	void GrvQuestion_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowIndex >= 0)
		{
			for (int i = 0; i < e.Row.Cells.Count; i++)
			{
				HyperLink hLink = new HyperLink();

				hLink.Text = e.Row.Cells[i].Text;
				hLink.Target = "_blank";
				hLink.NavigateUrl = "QuestionDetail.aspx?QuestionID=" + GrvQuestion.DataKeys[e.Row.RowIndex].Value.ToString();

				e.Row.Cells[i].Controls.Add(hLink);
			}
		}
	}

	void GrvExpertNews_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowIndex >= 0)
		{
			for (int i = 0; i < e.Row.Cells.Count; i++)
			{
				HyperLink hLink = new HyperLink();

				hLink.Text = e.Row.Cells[i].Text;
				hLink.Target = "_blank";
				hLink.NavigateUrl = "ExpertNewsDetail.aspx?ExpertNewsID=" + GrvExpertNews.DataKeys[e.Row.RowIndex].Value.ToString();

				e.Row.Cells[i].Controls.Add(hLink);
			}
		}
	}

	void GrvExpertGain_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowIndex >= 0)
		{
			for (int i = 0; i < e.Row.Cells.Count; i++)
			{
				HyperLink hLink = new HyperLink();

				hLink.Text = e.Row.Cells[i].Text;
				hLink.Target = "_blank";
				hLink.NavigateUrl = "ExpertGainDetail.aspx?ExpertGainID=" + GrvExpertGain.DataKeys[e.Row.RowIndex].Value.ToString();

				e.Row.Cells[i].Controls.Add(hLink);
			}
		}
	}

	///// <summary>
	///// 显示对大师的提问
	///// </summary>
	//private void ShowQuestion()
	//{
	//        List<PX.Question.Entity> listQuestion = new List<PX.Question.Entity>();

	//        listQuestion = clsQuestionComp.QueryAll();

	//        for (int i = 0; (i < listQuestion.Count) && (i < 8); i++)
	//        {
	//                PX.Answer.Entity clsAnswer = new PX.Answer.Entity();

	//                Image img = new Image();
	//                TableRow tabRow = new TableRow();
	//                TableCell tabCell1 = new TableCell();
	//                TableCell tabCell2 = new TableCell();
	//                TableCell tabCell3 = new TableCell();
	//                TableCell tabCell4 = new TableCell();
	//                TableCell tabCell5 = new TableCell();
	//                TableCell tabCell6 = new TableCell();
	//                TableCell tabCell7 = new TableCell();
	//                HyperLink hLinkQuestionDetail = new HyperLink();

	//                clsAnswer = clsAnswerComp.GetOne(listQuestion[i].AnswerID);

	//                img.ImageUrl = "../Skin/Images/图标.png";

	//                tabCell1.Controls.Add(img);
	//                //tabCell2.Text = listQuestion[i].Content;
	//                hLinkQuestionDetail.Text = listQuestion[i].Content;
	//                hLinkQuestionDetail.NavigateUrl = "QuestionDetail.aspx?QuestionID=" + listQuestion[i].ID.ToString() ;
	//                hLinkQuestionDetail.Target = "_blank";
	//                tabCell2.Controls.Add(hLinkQuestionDetail);
	//                tabCell3.Text = listQuestion[i].AskerName;
	//                tabCell4.Text = listQuestion[i].DateTime;
	//                //tabCell5.Text = listQuestion[i];
	//                tabCell5.Text = listQuestion[i].ExpertName;
	//                tabCell6.Text = listQuestion[i].HaveAnswerName;
	//                tabCell7.Text = listQuestion[i].AnswerDateTime;

	//                tabRow.Controls.Add(tabCell1);
	//                tabRow.Controls.Add(tabCell2);
	//                tabRow.Controls.Add(tabCell3);
	//                tabRow.Controls.Add(tabCell4);
	//                tabRow.Controls.Add(tabCell5);
	//                tabRow.Controls.Add(tabCell6);
	//                tabRow.Controls.Add(tabCell7);
	//                tabQuestion.Controls.Add(tabRow);
	//        }
	//}

	private void ShowQuestion()
	{
		GrvQuestion.DataSource = clsQuestionComp.QueryAll();
		GrvQuestion.DataKeyNames = new string[] { "ID" };
		GrvQuestion.DataBind();
	}

	/// <summary>
	/// 显示大师动态
	/// </summary>
	private void ShowExpertNews()
	{
		PX.File.FileComponent clsFileComp = new PX.File.FileComponent();

		clsFileComp.page = Page;

		GrvExpertNews.DataSource = clsFileComp.QueryFirstFile2(10, 125);
		GrvExpertNews.DataKeyNames = new string[] { "ID" };
		GrvExpertNews.DataBind();
	}

	/// <summary>
	/// 显示大师成果
	/// </summary>
	private void ShowExpertGain()
	{
		GrvExpertGain.DataSource = clsExpertGainComp.QueryAll();
		GrvExpertGain.DataKeyNames = new string[] { "ID" };
		GrvExpertGain.DataBind();
	}

	/// <summary>
	/// 显示大师课件
	/// </summary>
	private void ShowCourseware()
	{
		GrvCourseware.DataSource = clsCoursewareComp.QueryAll();
		GrvCourseware.DataKeyNames = new string[] { "ID" };
		GrvCourseware.DataBind();
	}
}
